package com.maomao.maomaochong_i.quanxing;

import android.util.Log;

import com.maomao.maomaochong_i.quanxing.PhoneData.PhoneData;

import java.util.ArrayList;

/**
 * Created by Mrma on 17.5.19.
 */

public class Phone implements Subject {
    private ArrayList<Xiugai> observer;
    private PhoneData phoneData;

    private static Phone guoWu;

    public static Phone getOne(){
        if (guoWu == null)
            guoWu = new Phone();
        return guoWu;
    }

    private Phone(){
        observer = new ArrayList<>();
    }
    @Override
    public void tianjia(Xiugai zhi) {
        observer.add(zhi);
    }

    @Override
    public void yichu(Xiugai o) {
        int i = observer.indexOf(o);
        if(i >= 0)
            observer.remove(i);
    }

    @Override
    public void tongzhi() {

        for (int i = 0 ; i<observer.size();i++){
            Xiugai xiugai = observer.get(i);

            xiugai.xiugai(phoneData);
        }
    }

    void setShu(PhoneData phoneData){
        this.phoneData = phoneData;
        tongzhi();
    }

}
